home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / histogram / maxval2d.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-18  |  3.2 KB  |  141 lines

  1. /* gsl_histogram2d_maxval.c
  2.  * Copyright (C) 2000  Simone Piccardi
  3.  *
  4.  * This library is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License as
  6.  * published by the Free Software Foundation; either version 2 of the
  7.  * License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.  * General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public
  15.  * License along with this library; if not, write to the
  16.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.  * Boston, MA 02111-1307, USA.
  18.  */
  19. /***************************************************************
  20.  *
  21.  * File gsl_histogram2d_maxval.c: 
  22.  * Routine to find maximum and minumum content of a 2D hisogram. 
  23.  * Need GSL library and header.
  24.  * Contains the routines:
  25.  * gsl_histogram2d_max_val find max content values
  26.  * gsl_histogram2d_min_val find min content values
  27.  * gsl_histogram2d_bin_max find coordinates of max contents bin
  28.  * gsl_histogram2d_bin_min find coordinates of min contents bin
  29.  *
  30.  * Author: S. Piccardi
  31.  * Jan. 2000
  32.  *
  33.  ***************************************************************/
  34. #include <config.h>
  35. #include <gsl/gsl_errno.h>
  36. #include <gsl/gsl_histogram2d.h>
  37. /*
  38.  * Return the maximum contents value of a 2D histogram
  39.  */
  40. double
  41. gsl_histogram2d_max_val (const gsl_histogram2d * h)
  42. {
  43.   const size_t nx = h->nx;
  44.   const size_t ny = h->ny;
  45.   size_t i;
  46.   double max = h->bin[0 * ny + 0];
  47.  
  48.   for (i = 0; i < nx * ny; i++)
  49.     {
  50.       if (h->bin[i] > max)
  51.     {
  52.       max = h->bin[i];
  53.     }
  54.     }
  55.   return max;
  56. }
  57.  
  58. /*
  59.  * Find the bin index for maximum value of a 2D histogram
  60.  */
  61.  
  62. void
  63. gsl_histogram2d_max_bin (const gsl_histogram2d * h, size_t * imax_out, size_t * jmax_out)
  64. {
  65.   const size_t nx = h->nx;
  66.   const size_t ny = h->ny;
  67.   size_t imax = 0, jmax = 0, i, j;
  68.   double max = h->bin[0 * ny + 0];
  69.  
  70.   for (i = 0; i < nx; i++)
  71.     {
  72.       for (j = 0; j < ny; j++)
  73.     {
  74.       double x = h->bin[i * ny + j];
  75.  
  76.       if (x > max)
  77.         {
  78.           max = x;
  79.           imax = i;
  80.           jmax = j;
  81.         }
  82.     }
  83.     }
  84.  
  85.   *imax_out = imax;
  86.   *jmax_out = jmax;
  87. }
  88.  
  89. /*
  90.  * Return the minimum contents value of a 2D histogram
  91.  */
  92.  
  93. double
  94. gsl_histogram2d_min_val (const gsl_histogram2d * h)
  95. {
  96.   const size_t nx = h->nx;
  97.   const size_t ny = h->ny;
  98.   size_t i;
  99.   double min = h->bin[0 * ny + 0];
  100.  
  101.   for (i = 0; i < nx * ny; i++)
  102.     {
  103.       if (h->bin[i] < min)
  104.     {
  105.       min = h->bin[i];
  106.     }
  107.     }
  108.  
  109.   return min;
  110. }
  111. /*
  112.  * Find the bin index for minimum value of a 2D histogram
  113.  */
  114. void
  115. gsl_histogram2d_min_bin (const gsl_histogram2d * h, size_t * imin_out, size_t * jmin_out)
  116. {
  117.   const size_t nx = h->nx;
  118.   const size_t ny = h->ny;
  119.   size_t imin = 0, jmin = 0, i, j;
  120.   double min = h->bin[0 * ny + 0];
  121.  
  122.   for (i = 0; i < nx; i++)
  123.     {
  124.       for (j = 0; j < ny; j++)
  125.     {
  126.       double x = h->bin[i * ny + j];
  127.  
  128.       if (x < min)
  129.         {
  130.           min = x;
  131.           imin = i;
  132.           jmin = j;
  133.         }
  134.     }
  135.     }
  136.  
  137.   *imin_out = imin;
  138.   *jmin_out = jmin;
  139. }
  140.  
  141.